﻿using System;
using System.Web.Mvc;

namespace Travel.MVC
{
    /// <summary>
    /// 禁止页面缓存
    /// </summary>
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
    public sealed class NonClientCacheAttribute : ActionFilterAttribute
    {
        /// <summary>
        /// Called by the MVC framework before the action method executes.
        /// </summary>
        /// <param name="filterContext">The filter context.</param>
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var response = filterContext.HttpContext.Response;
            response.Buffer = true;
            response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
            response.Expires = 0;
            response.CacheControl = "No-Cache";
        }
    }
}